/**
 *
 * @author 
 *
 */
class LoadingView extends eui.Component{
    
    private im_loading: eui.Image;
    private load1: eui.Image;
    private load2: eui.Image;
    private load3: eui.Image;
    private timer: egret.Timer;
    private step: number = 0;
    
    private static _instance: LoadingView;
    public static getInstance(): LoadingView {
        if(LoadingView._instance == null) {
            LoadingView._instance = new LoadingView();
        }
        return LoadingView._instance;
    }
    
	public constructor() {
    	  super();
        this.skinName = "resource/skins/LoadingSkin.exml";
        this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onAdd,this);
	}
	
    public createChildren() {
        super.createChildren();
    }
    
    private onAdd(): void {
        egret.setTimeout(this.add,this,100);
    }
    private add() {
        Main.getInstance().loadPreload();
        this.init();
    }
    
    private init() {
        egret.Tween.get(this,{ loop: true }).to({ t: Math.PI * 2 },800);
        this.timer = new egret.Timer(200);
        this.timer.addEventListener(egret.TimerEvent.TIMER,this.vdian,this);
        this.timer.start();
    }

    private vdian() {
        this.step++;
        if(this.step == 2) {
            this.load2.visible = true;
            this.load3.visible = false;
        } else if(this.step == 3) {
            this.load2.visible = true;
            this.load3.visible = true;
        } else if(this.step == 4) {
            this.load2.visible = false;
            this.load3.visible = false;
            this.step = 1;
        }
    }
    private _t: number = 0;
    get t(): number { return this._t; }
    set t(value: number) {
        this._t = value;
        this.im_loading.scaleX = Math.sin(value) * 0.05 + 1;
        this.im_loading.scaleY = Math.sin(value - Math.PI / 2) * 0.05 + 1;
    }
}
